using JGSY.CMS.LowCode.Platform.Domain.Enums;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 工作流任务实体
    /// 用于表示工作流中的具体任务实例和执行状态
    /// </summary>
    [Table("workflow_tasks")]
    public class WorkflowTask : ITenantEntity
    {
        /// <summary>
        /// 工作流任务标识符
        /// </summary>
        [Key]
        public long Id { get; set; }
        
        /// <summary>
        /// 租户ID
        /// 用于多租户数据隔离
        /// </summary>
        [Required]
        [StringLength(36)]
        [Column("tenant_id")]
        public string TenantId { get; set; } = string.Empty;
        
        /// <summary>
        /// 工作流实例标识符
        /// 该任务所属的工作流实例ID
        /// </summary>
        [Required]
        public long InstanceId { get; set; }
        
        /// <summary>
        /// 任务名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public required string TaskName { get; set; }
        
        /// <summary>
        /// 节点名称
        /// 任务所在的工作流节点名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public required string NodeName { get; set; }
        
        /// <summary>
        /// 指派人标识符
        /// 被指派处理该任务的用户ID
        /// </summary>
        [Required]
        public long AssigneeId { get; set; }
        
        /// <summary>
        /// 任务状态
        /// </summary>
        [Required]
        public WorkflowTaskStatus Status { get; set; } = WorkflowTaskStatus.Pending;
        
        /// <summary>
        /// 任务优先级
        /// 任务的优先级别，数值越大优先级越高
        /// </summary>
        public int Priority { get; set; } = 0;
        
        /// <summary>
        /// 截止时间
        /// 任务的完成截止时间
        /// </summary>
        public DateTime? DueDate { get; set; }
        
        /// <summary>
        /// 创建时间
        /// 任务的创建时间戳
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }
        
        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime? CompletedAt { get; set; }
        
        /// <summary>
        /// 任务备注
        /// </summary>
        [StringLength(1000)]
        public string? Comments { get; set; }
        
        /// <summary>
        /// 任务数据
        /// JSON格式的任务相关数据
        /// </summary>
        [Column(TypeName = "text")]
        public string? TaskData { get; set; }
        
        // Navigation properties
        [ForeignKey(nameof(InstanceId))]
        public virtual WorkflowInstance? Instance { get; set; }
        
        [ForeignKey(nameof(AssigneeId))]
        public virtual User? Assignee { get; set; }
    }
}
